package daos

import (
	"gorm.io/plugin/soft_delete"
)

var OrmS = []Orm{&Admin{}, &Role{}, &AdminRole{}, &RolePermission{}, &Logs{}}

type Orm interface {
	TableName() string
}

type OrmCreate struct {
	ID        int   `gorm:"type:int;AUTO_INCREMENT;column:id;comment:主键自增ID" json:"id"`
	CreatedAt *Time `gorm:"type:timestamp;column:created_at;comment:创建时间" json:"createTime"`
}

type OrmUpdate struct {
	ID        int   `gorm:"type:int;AUTO_INCREMENT;column:id;comment:主键自增ID" json:"id"`
	CreatedAt *Time `gorm:"type:timestamp;column:created_at;comment:创建时间" json:"createTime"`
	UpdatedAt *Time `gorm:"type:timestamp;column:updated_at;comment:更新时间" json:"updateTime"`
}

type OrmDel struct {
	ID        int                   `gorm:"type:int;AUTO_INCREMENT;column:id;comment:主键自增ID" json:"id"`
	CreatedAt *Time                 `gorm:"type:timestamp;column:created_at;comment:创建时间" json:"createTime"`
	UpdatedAt *Time                 `gorm:"type:timestamp;column:updated_at;comment:更新时间" json:"updateTime"`
	DeletedAt *Time                 `gorm:"type:timestamp;column:deleted_at;comment:删除时间" json:"deleteTime"`
	Deleted   soft_delete.DeletedAt `gorm:"type:tinyint(1);softDelete:flag,DeletedAtField:DeletedAt;column:deleted;comment:是否删除 1：是 0： 否" json:"deleted"`
}

type Admin struct {
	OrmDel
	Username string `gorm:"not null;type:varchar(20);uniqueIndex;column:username;comment:用户登录名称" json:"username"`
	Password string `gorm:"type:varchar(100);column:password;comment:密码" json:"password"`
	Nickname string `gorm:"type:varchar(100);column:nickname;comment:用户昵称" json:"nickname"`
	IsAdmin  int8   `gorm:"type:tinyint(1);default:0;column:is_admin;comment:是否为管理员 1：是 0： 否" json:"isAdmin"`
	Enabled  int8   `gorm:"type:tinyint(1);default:1;column:enabled;comment:是否可用 1：是 0： 否" json:"enabled"`
	Uuid     string `gorm:"type:varchar(100);column:uuid;comment:用户uuid" json:"uuid"`
}

func (Admin) TableName() string {
	return "tb_admins"
}

type Role struct {
	OrmDel
	Role string `gorm:"not null;type:varchar(20);column:role_name;comment:角色名称" json:"role"`
}

func (Role) TableName() string {
	return "tb_roles"
}

type AdminRole struct {
	OrmCreate
	AdminId int `gorm:"column:admin_id;comment:管理员ID" json:"adminId"`
	RoleId  int `gorm:"column:role_id;comment:角色ID" json:"roleId"`
}

func (AdminRole) TableName() string {
	return "tb_admins_roles"
}

type RolePermission struct {
	OrmCreate
	RoleId       int   `gorm:"column:role_id;comment:角色ID" json:"roleId"`
	PermissionId int32 `gorm:"column:permission_id;comment:权限ID" json:"permissionId"`
	MenuId       int32 `gorm:"column:menu_id;comment:菜单ID" json:"menuId"`
}

func (v RolePermission) TableName() string {
	return "tb_roles_permission"
}

type Logs struct {
	OrmCreate
	Username  string `gorm:"type:varchar(50);column:username;comment:用户昵称" json:"username"`
	Url       string `gorm:"type:varchar(50);column:url;comment:请求的路由" json:"url"`
	Method    string `gorm:"type:varchar(10);column:method;comment:请求方式" json:"method"`
	Success   int8   `gorm:"default:0;type:tinyint;column:success;comment:是否成功返回1:是0：否" json:"success"`
	Request   string `gorm:"type:text;column:request;comment:请求数据" json:"request"`
	Response  string `gorm:"type:text;column:response;comment:响应数据" json:"response"`
	IP        string `gorm:"type:varchar(20);column:ip;comment:IP" json:"ip"`
	UserAgent string `gorm:"type:varchar(255);column:user_agent;comment:客户端" json:"userAgent"`
}

func (v Logs) TableName() string {
	return "tb_logs"
}
